CHARTS
Photo by Paolo Bendandi on Unsplash
Count your age by friends, not years. Count your life by smiles, not tears.
— John Lennon
df <- read.csv('archetypes/older-versus-younger/IHME_GBD_2017_POP.csv', header = TRUE, stringsAsFactors = FALSE, encoding = "UTF-8")
df
age_levels <- c(
"Under 5",
"5 to 9",
"10 to 14",
"15 to 19",
"20 to 24",
"25 to 29",
"30 to 34",
"35 to 39",
"40 to 44",
"45 to 49",
"50 to 54",
"55 to 59",
"60 to 64",
"65 to 69",
"70 to 74",
"75 to 79",
"80 to 84",
"85 to 89",
"90 to 94",
"95 plus")
# Select and filter rows
# unique(df$age_group_name)
# unique(df$location_name)
df_wrangle <- df[,c(2,4,6,7,11)]%>%
filter(str_detect(location_name, 'SDI'))%>%
filter(sex_name!="Both")%>%
filter(age_group_name %in% age_levels) %>%
filter(year_id == 2017)
# Remove duplicate records
df_wrangle <- unique(df_wrangle)
## barplots for male populations goes to the left (thus negative sign)
df_wrangle$val <- ifelse(df_wrangle$sex_name == "Male", -1 * df_wrangle$val, df_wrangle$val)
df_wrangle
The Socio-Demographic Index (SDI) is: “A summary measure that identifies where countries or other geographic areas sit on the spectrum of development. Expressed on a scale of 0 to 1, SDI is a composite average of the rankings of the incomes per capita, average educational attainment, and fertility rates of all areas in the GBD study.”
theme_opts <- theme(
text = element_text(family = "inconsolata"),
plot.title = element_text(color = "black", size = 14, face = "bold"),
plot.subtitle = element_text(color = "black", size = 12),
plot.caption = element_text(color = "#555555", size = 10),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
axis.text = element_text(family = "inconsolata", size = 14),
panel.border = element_blank(),
panel.background = element_blank(),
panel.grid.minor = element_blank(),
panel.grid.major.x = element_blank(),
legend.title = element_blank(),
legend.text = element_text(color = "black", size = 11),
legend.position='bottom'
)
series_palette <- c(
"Low SDI" = "#E53935",
"Low-middle SDI" = "#FB8C00",
"Middle SDI" = "#90A4AE",
"High-middle SDI" = "#B0BEC5",
"High SDI" = "#CFD8DC"
)
gender_map <- data.frame(
gender = c("Male", "Female"),
x = c("95 plus", "95 plus"),
y = c(-50000000, 50000000)
)
v1 <- ggplot() +
geom_step(data=subset(df_wrangle, sex_name == "Female"), aes(x = factor(age_group_name, levels = age_levels ), y = val, color = location_name, group = location_name), size = 2) +
geom_step(data=subset(df_wrangle, sex_name == "Male"), aes(x = factor(age_group_name, levels = age_levels ), y = val, color = location_name, group = location_name), size = 2) +
geom_text(data = gender_map, aes(x = x, y = y, label = gender), size = 6, color = "black", vjust = 0.0, nudge_x = 0.1, hjust = 0.5, family = "inconsolata") +
scale_y_continuous(name="Population (millions)",breaks=c(-100000000,-50000000,0,50000000,100000000), labels = c("100m","50m","0","50m","100m")) +
scale_color_manual(values = series_palette) +
coord_flip() +
theme_minimal() +
theme_opts
girafe(ggobj = v1, width_svg = 1280/72, height_svg = 1080/72,
options = list(opts_sizing(rescale = FALSE, width = 1.0))
)
age_df <- data.frame( age_level = age_levels )
v2 <- ggplot() +
geom_step(data=subset(df_wrangle, sex_name == "Female"), aes(x = factor(age_group_name, levels = age_levels ), y = val, color = location_name, group = location_name), size = 2) +
geom_step(data=subset(df_wrangle, sex_name == "Male"), aes(x = factor(age_group_name, levels = age_levels ), y = val, color = location_name, group = location_name), size = 2) +
geom_text(data = gender_map, aes(x = x, y = y, label = gender), size = 6, color = "black", vjust = 0.0, nudge_x = 0.1, hjust = 0.5, family = "inconsolata") +
geom_label(data = age_df, aes(x = age_level, y = 0, label = age_level), size = 4, color = "black", vjust = 0.5, hjust = 0.5, family = "inconsolata") +
scale_y_continuous(name="Population(millions)",breaks=c(-100000000,-50000000,0,50000000,100000000), labels = c("100m","50m","0","50m","100m")) +
scale_color_manual(values = series_palette) +
coord_flip() +
theme_minimal() +
theme_opts +
theme(
axis.text.y = element_blank()
)
girafe(ggobj = v2, width_svg = 1280/72, height_svg = 1080/72,
options = list(opts_sizing(rescale = FALSE, width = 1.0))
)